home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / lib / filename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-20  |  2.5 KB  |  100 lines

  1. /* filename.c: routines to manipulate filenames.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20. #include "paths.h"
  21.  
  22. #include "filename.h"
  23. #include "pathsrch.h"
  24.  
  25.  
  26. /* Try to find the PK font FONT_NAME at resolution DPI, using various
  27.    paths (see `filename.h').  The filename must have the resolution as
  28.    part of the extension, e.g., `cmr10.300pk', for it to be found.  */
  29.    
  30. string
  31. find_pk_filename (string font_name, unsigned dpi)
  32. {
  33.   static string *dirs = NULL;
  34.   string pk_var, pk_name, name;
  35.   char suffix[MAX_INT_LENGTH + sizeof ".pk"];
  36.  
  37.   sprintf (suffix, ".%dpk", dpi);
  38.  
  39.   pk_var = getenv ("PKFONTS") ? "PKFONTS"
  40.            : getenv ("TEXPKS") ? "TEXPKS" : "TEXFONTS";
  41.  
  42.   if (dirs == NULL)
  43.     dirs = initialize_path_list (pk_var, DEFAULT_PK_PATH);
  44.  
  45.   name = concat (font_name, suffix);
  46.   pk_name = find_path_filename (name, dirs);
  47.  
  48.   if (name != pk_name)
  49.     free (name);
  50.   
  51.   return pk_name;
  52. }
  53.  
  54.  
  55. /* Like `find_pk_filename', but search for a font in GF format.  */
  56.  
  57. string
  58. find_gf_filename (string font_name, unsigned dpi)
  59. {
  60.   static string *dirs = NULL;
  61.   string gf_var, gf_name, name;
  62.   char suffix[MAX_INT_LENGTH + sizeof ".pk"];
  63.  
  64.   sprintf (suffix, ".%dgf", dpi);
  65.  
  66.   gf_var = getenv ("GFFONTS") ? "GFFONTS" : "TEXFONTS";
  67.   
  68.   if (dirs == NULL)
  69.     dirs = initialize_path_list (gf_var, DEFAULT_GF_PATH);
  70.  
  71.   name = concat (font_name, suffix);
  72.   gf_name = find_path_filename (name, dirs);
  73.  
  74.   if (name != gf_name)
  75.     free (name);
  76.     
  77.   return gf_name;
  78. }
  79.  
  80.  
  81. /* Like `find_pk_filename', except search for a TFM file.  */
  82.  
  83. string
  84. find_tfm_filename (string font_name)
  85. {
  86.   static string *dirs = NULL;
  87.   string tfm_name, name;
  88.  
  89.   if (dirs == NULL)
  90.     dirs = initialize_path_list ("TEXFONTS", DEFAULT_TFM_PATH);
  91.  
  92.   name = concat (font_name, ".tfm");
  93.   tfm_name = find_path_filename (name, dirs);
  94.  
  95.   if (name != tfm_name)
  96.     free (name);
  97.     
  98.   return tfm_name; 
  99. }
  100.